<?php
	session_start();
    if(!isset($_SESSION["userName"]) or $_SESSION["userType"] !== "qc") {
    	header("location: accesserror.php");
    }
    header("text/html;charset=utf8");
	$result = "?result=";
	if ($username === "") { 
	  		$result .= "用户名不能为空";
	} 
  	else {
  		$connect = mysql_connect("localhost","root","yxs147789");
		if ($connect) {
		  	mysql_select_db("inspectdb", $connect);
		  	mysql_query("set names 'utf8'");
		  	$username = trim($_POST['username']);
		  	$passwd = $_POST['passwd'];
		  	$type = $_POST['type'];
		  	$querystr = sprintf("INSERT INTO users(user_name, pass_wd, type) VALUES ('%s', '%s', '%s')", $username, $passwd, $type);
		  	//echo $querystr;
		  	if(mysql_query($querystr)) {
		  		$result .= "success";
		  	} else {
		  		$result .= "已存在相同用户名";
		  	}
		} else { 
			$result .= "连接失败";
		}
		mysql_close($connect);
	}
	header("location: addpop.php" . $result);
?>